﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using ReflectionStudio.Core.Events;
namespace WPFExcelReport
{
    public class AB45GAAUFReport : BaseReport
    {
        string strCompany = "HLT";
        string strExcelFile = "";
        string sheetName = "";
        string ABPAUFFKRS;
        string ABPAUFFLFD;
        string ABPAUFFPOS;
        string Standard = "AB45GAAUF";
        string filePath = @"C:\intex.w\Report\HLT\HLTPlanningReport.xls";
        public AB45GAAUFReport()
            : base()
        {
        }
        public AB45GAAUFReport(Dictionary<string, object> dicParamater)
            : base(dicParamater)
        {
            ABPAUFFKRS = dicParamater["ABPAUFKRS"].ToString().Trim();
            ABPAUFFLFD = dicParamater["ABPAUFLFD"].ToString().Trim();
            ABPAUFFPOS = dicParamater["ABPAUFPOS"].ToString().Trim();
            strCompany = dicParamater["Company"].ToString().Trim();
            strExcelFile = dicParamater["ExcelFile"].ToString().Trim();
            strExcelFile = @"HLT\HLTPlanningReport.xls"; 
            #region Excel  columns
            columns.Add("ORDERNO");
            columns.Add("FACTORY");
            columns.Add("ORDERDAT");
            columns.Add("ARTICLE");
            columns.Add("ORDERQTY");
            columns.Add("YARN");
            columns.Add("YARNDES");
            columns.Add("COLORDES");
            columns.Add("SPPART");
            columns.Add("REQWEI");
            columns.Add("ALLWEI");
            #endregion
        }
        public void FillInExcelData(ArrayList columns, DataSet setSoruce, int xStart = 2, int yStart = 1)
        {
            try
            {
                int x = xStart, y = yStart;
                DataTable dtSoruce = setSoruce.Tables["AB45GAAUF"];
                foreach (DataRow dataRow in dtSoruce.Rows)
                {
                    y = yStart;
                    foreach (string column in columns)
                    {
                        exAgent.SetCellValue(x, y, dataRow[column].ToString());
                        y++;
                    }
                    x++;
                }
               // HideNullRows();
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }
        private void HideNullRows()
        {
            try
            {
                int HidedRows = 0;
                int rowstart = 1;
                int rowend = 1;
                int col1, col2, col3;

                var val1 = exAgent.GetCellValue(1, 1);

                rowstart = 1; rowend = 500; col1 = 1; col2 = 2;
                for (int Rowi = rowstart; Rowi <= rowend; Rowi++)
                {
                    val1 = exAgent.GetRangeValue(Rowi, Rowi, col1, col2).Trim();
                    if ((string)val1 == "")
                    {
                        HidedRows++;
                        exAgent.HideRows(Rowi, col1, Rowi, col2);
                    }
                }
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }
        public override void WriteExcelReport(string fileType)
        {
            string filename = "";
            string sheetName = "";
            string Standard = "AB45GAAUF";
            strExcelFile = @"HLT\HLTPlanningReport.xls";
            string filePath = @"C:\intex.w\Report\" + strExcelFile;
            exAgent.Open(filePath);
            exAgent.Company = strCompany;
            exAgent.strExcelFile = strExcelFile;
            string filedate = ABPAUFFKRS + "-" + ABPAUFFLFD + "-" + ABPAUFFPOS;
            filename = @"浆纱配纱情况" + filedate + ".xls";
            sheetName = filedate;
            exAgent.CreateNewSheet(filename, Standard, sheetName);
            FillInExcelData(columns, dsSource, 4, 1);
            base.WriteExcelReport(fileType);
        }
    }
}
